﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OracleClient;
using BLL.SystemManagement;
using Garlic.CC.BaseClass;

namespace Garlic.UserControls
{
    public partial class ServiceRouteTreePop : System.Web.UI.UserControl
    {
        public IUser iuser { get; set; }


        public string ServiceRouteID
        {
            get
            {
                return hiddenfieldServiceRoutePop.Value;
            }
            set
            {
                txtServiceRoutePop.Text = value;
            }
        }

        public string ServiceRouteText
        {
            get
            {
                return txtServiceRoutePop.Text;
            }
            set
            {
                txtServiceRoutePop.Text = value;
            }
        }
        public int Width
        {
            set
            {
                txtServiceRoutePop.Width = value;
            }
        }

        public int Height
        {
            set
            {
                txtServiceRoutePop.Height = value;
            }
        }

        public string CssClass
        {
            set
            {
                txtServiceRoutePop.CssClass = value;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindTreeData();
        }



        public void BindTreeData()
        {
            //TreeView1.DataSource 
            using (DataTable table = ServiceRouteTreeBLL.GetRoutes1(iuser.UserID, iuser.UserType))
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    TreeNode node = new TreeNode()
                    {
                        Text = Convert.ToString(table.Rows[i][1]),
                        Value = "0",
                        NavigateUrl = "javascript:void(0)"
                    };
                    using (DataTable table2 = ServiceRouteTreeBLL.GetRoutes2(iuser.UserID, iuser.UserType, Convert.ToInt32(table.Rows[i][0])))
                    {
                        if (table2.Rows.Count > 0)
                        {
                            for (int j = 0; j < table2.Rows.Count; j++)
                            {
                                TreeNode node2 = new TreeNode()
                                {
                                    Text = Convert.ToString(table2.Rows[j][1]),
                                    Value = Convert.ToString(table2.Rows[j][0]),
                                    NavigateUrl = String.Format("javascript:setvaluePop('{0}','{1}');", Convert.ToString(table2.Rows[j][1]), Convert.ToString(table2.Rows[j][0]))
                                };
                                using (DataTable table3 = ServiceRouteTreeBLL.GetRoutes3(iuser.UserID, iuser.UserType, Convert.ToInt32(table2.Rows[j][0])))
                                {
                                    if (table3.Rows.Count > 0)
                                    {
                                        node2.NavigateUrl = "javascript:void(0)";
                                        for (int k = 0; k < table3.Rows.Count; k++)
                                        {
                                            TreeNode node3 = new TreeNode()
                                            {
                                                Text = Convert.ToString(table3.Rows[k][1]),
                                                Value = Convert.ToString(table3.Rows[k][0]),
                                                NavigateUrl = String.Format("javascript:setvaluePop('{0}','{1}');", Convert.ToString(table3.Rows[k][1]), Convert.ToString(table3.Rows[k][0]))
                                            };
                                            node2.ChildNodes.Add(node3);
                                        }
                                    }
                                }
                                node.ChildNodes.Add(node2);
                            }
                        }
                    }
                    PopServiceRouteTreeView.Nodes.Add(node);
                }
            }
        }
    }
}

